package liecai_class.day08;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

public class Demo07 {
    static CountDownLatch cdl = new CountDownLatch(2);
    static AtomicInteger x = new AtomicInteger(0);
    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=0;i<100000;i++){
//                    while(!x.compareAndSet(x.get(),x.get()+1)){
//                    }
                    x.getAndIncrement();
                }
                cdl.countDown();
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=0;i<100000;i++){
//                    while(!x.compareAndSet(x.get(),x.get()+1)){
//                    }
                    x.getAndIncrement();
                }
                cdl.countDown();
            }
        }).start();

        cdl.await();
        System.out.println(x);
    }
}